<script lang="ts">
export default {
    name: "Selector",
    methods:{
        goSearch(propsStr){
            // 获取查询字符串中的props属性
            let {props=[]} = this.$route.query;
            // 如果不是数组，将其转为数组
            if(!Array.isArray(props)) props=[props];
            // 如果已经包含相同的，那么后续的代码不需要执行
            if(props.includes(propsStr)) return;
            props = [
                ...props.filter(item=>item.split(":")[0] !== propsStr.split(":")[0]),
                propsStr
            ];
            this.$router.push({
                path:"/search",
                query:{
                    ...this.$route.query,
                    props
                }
            })
        }

    }
}
</script>

<template>
    <div class="clearfix selector">
        <div class="type-wrap logo">
            <div class="fl key brand">品牌</div>
            <div class="value logos">
                <ul class="logo-list">
                    <li :class="{
                        active:$route.query.trademark=== item._id+':'+item.name
                    }" @click="$router.push({
                        path:'/search',
                        query:{
                            ...$route.query,
                            trademark:item._id+':'+item.name
                        }
                    })" :key="item._id" v-for="item in $store.state.product.searchResult.trademarkList">
                        <img :title="item.name" :src="'/img'+item.img" />
                    </li>
                </ul>
            </div>
        </div>

        <div v-for="item in $store.state.product.searchResult.attrsList" :key="item._id" class="type-wrap">
            <div class="fl key">{{item.name}}</div>
            <div class="fl value">
                <ul class="type-list">
                    <li v-for="title in item.attrValueList" :key="title.id">
                        <a :class="{
                            active:$route.query.props?.includes(item._id+':'+item.name+':'+title.id+':'+title.valueName)
                        }" @click.prevent="goSearch(item._id+':'+item.name+':'+title.id+':'+title.valueName)">{{title.valueName}}</a>
                    </li>

                </ul>
            </div>
            <div class="fl ext"></div>
        </div>
    </div>
</template>

<style scoped lang="less">
.selector{
    border: 1px solid #ddd;
    margin-bottom: 5px;
    overflow: hidden;
    .logo{
        border-top: 0;
        margin: 0;
        position: relative;
        overflow: hidden;
        .key{
            padding-bottom: 105px!important;
        }
    }
    .type-wrap{
        margin: 0;
        position: relative;
        border-top: 1px solid #ddd;
        overflow:hidden;
        .key{
            width: 100px;
            background: #f1f1f1;
            line-height: 26px;
            text-align: right;
            padding: 10px 10px 0 15px;
            float:left;
        }
        .value{
            overflow: hidden;
            padding: 10px 0 0 15px;
            color: #333;
            margin-left: 120px;
            //padding-right: 90px;
            .logo-list{
                li{
                    float: left;
                    border: 1px solid #e4e4e4;
                    margin: 1px;
                    padding:3px;
                    width: 107px;
                    height: 52px;
                    text-align: center;
                    line-height: 52px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    font-weight: 700;
                    color: #e1251b;
                    font-style: italic;
                    font-size: 14px;
                    img{
                        max-width: 100%;
                        vertical-align: middle;
                    }
                    &.active{
                        border:1px solid red;
                    }
                    &:hover{
                        cursor: pointer;
                    }
                }
            }
            .type-list{
                li{
                    float: left;
                    display: block;
                    margin-right: 30px;
                    line-height: 26px;
                    a{
                        text-decoration: none;
                        color: #666;
                        &.active{
                            color:red;
                        }
                    }
                }
            }
        }
        .ext{
            position: absolute;
            top: 10px;
            right: 10px;
            .sui-btn{
                display: inline-block;
                padding: 2px 14px;
                box-sizing: border-box;
                margin-bottom: 0;
                font-size: 12px;
                line-height: 18px;
                text-align: center;
                vertical-align: middle;
                cursor: pointer;
                padding: 0 10px;
                background: #fff;
                border: 1px solid #d5d5d5;
            }
            a{
                color: #666;
            }
        }
    }
}
</style>
